// pages/integralconvertrecord/integralconvertrecord.js
var app = getApp();
var GlobalData = require('../../utils/GlobalData.js');
var dataManager = require('../../utils/dataManager.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordArr: [],
    loading: false,
    arrlength: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    dataManager.rigisterObserver("getordernos", this.onComplete, this);
    dataManager.getExchangeRecordDm(3, 1, 10, false);
  },
  onComplete() {

    if (GlobalData.exchangeRecord["3"].length == this.arrlength)
      return;
    this.data.recordArr = GlobalData.exchangeRecord["3"];
    for (let i = 0; i < this.data.recordArr.length; i++) {
      if (this.data.recordArr[i]["createtime"]) {
        this.data.recordArr[i]["createtime"] = this.data.recordArr[i]["createtime"].replace("T", " ")
      }
      for (let k = 0; k < this.data.recordArr[i].items.length; k++) {
        for (let j = 0; j < this.data.recordArr[i].items[k].img.length; j++) {
          if (this.data.recordArr[i].items[k].img[j].sortno == 3) {
            this.data.recordArr[i].items[k]['image'] = this.data.recordArr[i].items[k].img[j].path;
          }
        }
      }
    }
    this.data.loading = false;
    this.data.arrlength = this.data.recordArr.length;
    this.setData({
      recordArr: this.data.recordArr,
      arrlength: this.data.arrlength,
      loading: this.data.loading
    })
  },
  onScrollSlide() {

    if (!this.data.loading) {
      this.data.loading = true;
      GlobalData.exchangeRecordPage[3] += 1;
      dataManager.rigisterObserver("getordernos", this.onComplete, this);
      dataManager.getExchangeRecordDm(3, GlobalData.exchangeRecordPage[3], 10, true);
    }
  },
   goDetails(e) {
    console.log(e);
    let id = e.currentTarget.dataset.item.detailid;
   dataManager.rigisterObserver("getgoodsdetails", this.getGoodsDetails, this);
    dataManager.getProductDetails(id);
  },
  /**获取商品详情的回调函数 */
  getGoodsDetails() {
    dataManager.UseNavigateTo("/pages/productdetails/productdetails", false);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})